//
//  LCTaskService.m
//  lechuang
//
//  Created by Mr_hi on 2023/3/28.
//  Copyright © 2023 Mooyi. All rights reserved.
//

#import "LCTaskService.h"

@implementation LCTaskService

+(AFHTTPSessionManager *)sharedManager {
    static AFHTTPSessionManager *afnManage = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        afnManage = [AFHTTPSessionManager manager];
        afnManage.responseSerializer = [AFJSONResponseSerializer serializer];
        afnManage.requestSerializer = [AFJSONRequestSerializer serializer];
        [afnManage.requestSerializer setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
        afnManage.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/plain",@"text/html", nil];
    });
    return afnManage;
}

//获取公告
+ (void)getNoticeDataWithBlock:(void(^)(BOOL isSuccess, NSArray <LCNoticeModel *>* list))block {
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    [[XWXNetWorkQuery sharedManage] AFRequestData:Url(URLNotice) HttpMethod:KGet HaveToken:YES params:param completionHandle:^(id  _Nonnull result) {
        if ([[result objectForKey:@"success"] boolValue]) {
            NSArray * list = [LCNoticeModel mj_objectArrayWithKeyValuesArray:result[@"result"]];
            block(YES, list);
        } else {
            [self showErrorText:[result objectForKey:@"tips"]];
            block(NO, nil);
        }
    } errorHandle:^(NSError * _Nonnull error) {
        XWXNetError
        block(NO, nil);
    }];
}

//提交表单
+ (void)saveFormWithFormId:(NSString *)formId Other:(NSMutableDictionary *)other Block:(void(^)(BOOL isSuccess))block {
    other[@"FormID"] = formId;
    [[XWXNetWorkQuery sharedManage] AFRequestData:Url(URLSystemForm) HttpMethod:KGet HaveToken:YES params:other completionHandle:^(id  _Nonnull result) {
        if ([[result objectForKey:@"success"] boolValue]) {
            block(YES);
        } else {
            [self showErrorText:[result objectForKey:@"tips"]];
            block(NO);
        }
    } errorHandle:^(NSError * _Nonnull error) {
        XWXNetError
        block(NO);
    }];
}


//获取渠道信息
+ (void)getUnionDataWithBlock:(void(^)(BOOL isSuccess, NSArray <LCUnionModel *>* list))block {
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    [[XWXNetWorkQuery sharedManage] AFRequestData:Url(URLUnion) HttpMethod:KGet HaveToken:YES params:param completionHandle:^(id  _Nonnull result) {
        if ([[result objectForKey:@"success"] boolValue]) {
            NSArray * list = [LCUnionModel mj_objectArrayWithKeyValuesArray:result[@"result"]];
            block(YES, list);
        } else {
            [self showErrorText:[result objectForKey:@"tips"]];
            block(NO, nil);
        }
    } errorHandle:^(NSError * _Nonnull error) {
        XWXNetError;
        block(NO, nil);
    }];
}

//获取闪游任务列表
+ (void)getAreaTaskListWithAppId:(NSString *)appId Key:(NSString *)secretKey OrderType:(NSInteger)type PageNum:(NSInteger)page Block:(void(^)(BOOL isSuccess, NSArray <LCTaskModel *>* list, NSInteger hasData))block {
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    
    param[@"sdkChannelId"] = appId;
    param[@"sdkUserId"] = LCUserDefGet(Userid);
    param[@"sdkVersion"] = @"1";
    param[@"timestamp"] = [LCFunction getNowTimeTimestamp];
    param[@"pageSize"] = @"10";
    param[@"pageNum"] = kFORMAT(@"%ld",page);
    param[@"orderType"] = kFORMAT(@"%ld",type);
    
    NSMutableArray * paramStrArr = [LCFunction  keyVauleArrWithDictionary:param].mutableCopy;
    [paramStrArr addObject:[NSString stringWithFormat:@"key=%@",secretKey]];
    NSString * paramStr = [paramStrArr componentsJoinedByString:@"&"];
    NSString * sign = [[LCFunction ns_md5:paramStr] lowercaseString];
    param[@"sign"] = sign;
    
    [[LCTaskService sharedManager] POST:URLAreaTask parameters:param headers:@{} progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([responseObject[@"code"] integerValue] == 2000) {
            NSArray * list = [LCTaskModel mj_objectArrayWithKeyValuesArray:responseObject[@"extend"][@"list"]];
            NSInteger hasData = [responseObject[@"extend"][@"hasData"] integerValue];
            block(YES, list, hasData);
        } else {
            [self showErrorText:[responseObject objectForKey:@"message"]];
            block(NO, nil, 0);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        XWXNetError;
        block(NO, nil, 0);
    }];
}

//获取渠道赚任务列表
+ (void)getSearchTaskListWithPage:(NSInteger)page SearchKey:(NSString *)searchKey Block:(void(^)(BOOL isSuccess, NSArray <LCXunKaTaskModel *>* list, NSInteger total))block {
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"page"] = @(page);
    param[@"classname"] = @"渠道赚";
    param[@"Appname"] = searchKey;
    param[@"systemchar"] = @"苹果系统";
    
    [[XWXNetWorkQuery sharedManage] AFRequestData:Url(URLXunKaList) HttpMethod:KGet HaveToken:YES params:param completionHandle:^(id  _Nonnull result) {
        if ([[result objectForKey:@"success"] boolValue]) {
            NSArray * list = [LCXunKaTaskModel mj_objectArrayWithKeyValuesArray:result[@"result"]];
            NSInteger total = [result[@"record"] integerValue];
            block(YES, list, total);
        } else {
            [self showErrorText:[result objectForKey:@"tips"]];
            block(NO, nil, 0);
        }
    } errorHandle:^(NSError * _Nonnull error) {
        XWXNetError
        block(NO, nil, 0);
    }];
}

//获取多游任务列表
+ (void)getGameTaskListWithAppId:(NSString *)appId Key:(NSString *)secretKey PageNum:(NSInteger)page Block:(void(^)(BOOL isSuccess, NSArray <LCGameTaskModel *>* list))block {
    
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"media_id"] = appId;
    param[@"user_id"] = LCUserDefGet(Userid);
    param[@"device_type"] = @"1";
    
    NSMutableArray * paramStrArr = [LCFunction  keyVauleArrWithDictionary:param].mutableCopy;
    [paramStrArr addObject:[NSString stringWithFormat:@"key=%@",secretKey]];
    NSString * paramStr = [paramStrArr componentsJoinedByString:@"&"];
    NSString * sign = [[LCFunction ns_md5:paramStr] lowercaseString];
    
    param[@"size"] = @(10);
    param[@"page"] = @(page);
    param[@"sign"] = sign;
    
    [[LCTaskService sharedManager] GET:URLGameTask parameters:param headers:@{} progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([responseObject[@"status_code"] integerValue] == 200) {
            NSArray * list = [LCGameTaskModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]];
            block(YES, list);
        } else {
            [self showErrorText:[responseObject objectForKey:@"message"]];
            block(NO, nil);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        XWXNetError;
        block(NO, nil);
    }];
}

//获取卡商平台抽成比例
+ (void)getCardTaskPointWithBlock:(void(^)(BOOL isSuccess, CGFloat point))block {
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    [[XWXNetWorkQuery sharedManage] AFRequestData:Url(URLCardPoint) HttpMethod:KGet HaveToken:YES params:param completionHandle:^(id  _Nonnull result) {
        if ([[result objectForKey:@"success"] boolValue]) {
            NSString * point = result[@"field"][@"point"];
            CGFloat sysPoint = (100-point.integerValue)/100.0;
            block(YES, sysPoint);
        } else {
            [self showErrorText:[result objectForKey:@"tips"]];
            block(NO, 1.0);
        }
    } errorHandle:^(NSError * _Nonnull error) {
        XWXNetError
        block(NO, 1.0);
    }];
}

//获取卡商任务列表
+ (void)getHaoKaTaskListWithBlock:(void(^)(BOOL isSuccess, NSArray <LCCardTaskModel *>* list))block {

    NSDictionary *headers = [LCTaskService getHaoKaHeadersDic];
    
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    
    [[LCTaskService sharedManager] POST:URLHaoKaTask parameters:param headers:headers progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([responseObject[@"code"] integerValue] == 0) {
            NSArray * list = [LCCardTaskModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]];
            block(YES, list);
        } else {
            [self showErrorText:[responseObject objectForKey:@"message"]];
            block(NO, nil);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        XWXNetError;
        block(NO, nil);
    }];
}

//获取卡商任务详情
+ (void)getHaoKaTaskDetailWithId:(NSString *)Id Block:(void(^)(BOOL isSuccess, LCCardTaskModel *detail))block {
    
    NSDictionary *headers = [LCTaskService getHaoKaHeadersDic];
    
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"id"] = Id;
    
    [[LCTaskService sharedManager] POST:URLHaoKaTaskDetail parameters:param headers:headers progress:^(NSProgress * _Nonnull uploadProgress) {
            
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([responseObject[@"code"] integerValue] == 0) {
            LCCardTaskModel * detail = [LCCardTaskModel mj_objectWithKeyValues:responseObject[@"data"]];
            block(YES, detail);
        } else {
            [self showErrorText:[responseObject objectForKey:@"message"]];
            block(NO, nil);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        XWXNetError;
        block(NO, nil);
    }];
}

//卡商申请发送验证码
+ (void)sendCodeWithParam:(NSMutableDictionary *)param Block:(void(^)(BOOL isSuccess))block {
    NSDictionary *headers = [LCTaskService getHaoKaHeadersDic];
    [[LCTaskService sharedManager] POST:CardSendCodeUrl parameters:param headers:headers progress:^(NSProgress * _Nonnull uploadProgress) {
            
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([responseObject[@"code"] integerValue] == 0) {
            block(YES);
        } else {
            [self showErrorText:[responseObject objectForKey:@"msg"]];
            block(NO);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        XWXNetError;
        block(NO);
    }];
}

//卡商申请
+ (void)cardApplyWithParam:(NSMutableDictionary *)param Block:(void(^)(BOOL isSuccess))block {
    NSDictionary *headers = [LCTaskService getHaoKaHeadersDic];
    
    [[LCTaskService sharedManager] POST:CardApplyUrl parameters:param headers:headers progress:^(NSProgress * _Nonnull uploadProgress) {
            
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([responseObject[@"code"] integerValue] == 0) {
            block(YES);
        } else {
            [self showErrorText:[responseObject objectForKey:@"message"]];
            block(NO);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        XWXNetError;
        block(NO);
    }];
}


+ (NSDictionary *) getHaoKaHeadersDic {
    
    NSString * timestamp = [NSString GetTimeIntervalWithDate:[NSDate date]];
    NSString * traceId = [LCFunction ns_md5:timestamp];
    NSString * singStr = [NSString stringWithFormat:@"%@%@%@%@%@", HaoKaAppID,HaoKaApiVersion,traceId,timestamp,HaoKaAppKey];
    NSString * sign = [LCFunction ns_md5:singStr];

    NSDictionary *headers = @{
       @"appID": HaoKaAppID,
       @"apiVersion": HaoKaApiVersion,
       @"traceID": traceId,
       @"timestamp": timestamp,
       @"sign": sign,
       @"User-Agent": @"Apifox/1.0.0 (https://apifox.com)"
    };
    
    return headers;
}

//保存价格
+ (void)saveCardPriceWithGoodId:(NSString *)good_id Amount:(NSString *)amount Block:(void(^)(BOOL isSuccess))block {

    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"Goodid"] = good_id;
    param[@"thisAmount"] = amount;
    NSString * timestamp = [LCFunction getNowTimeTimestamp];
    param[@"Timestamp"] = timestamp;

    NSString * sign = [LCFunction ns_md5:kFORMAT(@"授权签名-|-|-%@-|-|-%@-|-|-%@-|-|-授权签名",LCUserDefGet(Userid),timestamp,amount)];
    param[@"SignKey"] = [sign substringToIndex:24].uppercaseString;

    [[XWXNetWorkQuery sharedManage] AFRequestData:Url(SaveTaskMoney) HttpMethod:KGet HaveToken:YES params:param completionHandle:^(id  _Nonnull result) {
        if ([[result objectForKey:@"success"] boolValue]) {
            block(YES);
        } else {
            [self showErrorText:[result objectForKey:@"tips"]];
            block(NO);
        }
    } errorHandle:^(NSError * _Nonnull error) {
        XWXNetError
        block(NO);
    }];
}

//获取讯卡商品列表
+ (void)xunKaTaskListWithPageNum:(NSInteger)page Block:(void(^)(BOOL isSuccess, NSArray <LCXunKaTaskModel *>* list, NSInteger total))block {
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"page"] = @(page);
    param[@"classname"] = @"信用卡区";
    [[XWXNetWorkQuery sharedManage] AFRequestData:Url(URLXunKaList) HttpMethod:KGet HaveToken:YES params:param completionHandle:^(id  _Nonnull result) {
        if ([[result objectForKey:@"success"] boolValue]) {
            NSArray * list = [LCXunKaTaskModel mj_objectArrayWithKeyValuesArray:result[@"result"]];
            NSInteger total = [result[@"record"] integerValue];
            block(YES, list, total);
        } else {
            [self showErrorText:[result objectForKey:@"tips"]];
            block(NO, nil, 0);
        }
    } errorHandle:^(NSError * _Nonnull error) {
        XWXNetError
        block(NO, nil, 0);
    }];
}

//获取申卡链接URL
+ (void)getApplyUrlWithParam:(NSMutableDictionary *)param Salt:(NSString *)salt Block:(void(^)(BOOL isSuccess, NSString *applyUrl))block {
    NSArray * keyArr = param.allKeys;
    NSArray * sortedArr = [keyArr sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        return [obj1 compare:obj2 options:NSNumericSearch];
    }];
    NSMutableArray * keyValueArr = [NSMutableArray array];
    for (NSString * key in sortedArr) {
        if ([LCFunction isEmptyString:param[key]]) {
            [keyValueArr addObject:[NSString stringWithFormat:@"%@%@",key, param[key]]];
        }
    }
    NSString * signStr = [keyValueArr componentsJoinedByString:@""];
    NSLog(@"signStr === %@\n\n\n\n",signStr);
    
    NSLog(@"md5(signStr) === %@\n\n\n\n",[LCFunction ns_md5:signStr]);
    
    NSString * sign =[LCFunction ns_md5:kFORMAT(@"%@%@",[LCFunction ns_md5:signStr].lowercaseString,salt)].uppercaseString;
    
    NSLog(@"sign ===  %@\n\n\n\n",sign);
    
    param[@"sign"] = sign;
    
    [[LCTaskService sharedManager] POST:URLGetApplyUrl parameters:param headers:@{} progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([responseObject[@"code"] integerValue] == 0) {
            NSString * applyUrl = responseObject[@"data"][@"applyUrl"];
            block(YES, applyUrl);
        } else {
            [self showErrorText:[responseObject objectForKey:@"msg"]];
            block(NO, @"");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        XWXNetError;
        block(NO, @"");
    }];
}

//下载任务应用
+ (void)downloadTaskAppWithAppID:(NSString *)appid LaunchID:(NSString *)launchid Block:(void(^)(BOOL isSuccess, NSDictionary *field))block {
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"AppID"] = appid;
    param[@"LaunchID"] = launchid;
    param[@"DeviceType"] = @"iOS";
    param[@"DeviceCode"] = [LCDeviceTool getIdfa];
    param[@"strEdition"] = [LCDeviceTool deviceVersion];
    param[@"strNetwork"] = [LCDeviceTool getMAC];
    
    [[XWXNetWorkQuery sharedManage] AFRequestData:Url(URLDownloadApp) HttpMethod:KGet HaveToken:YES params:param completionHandle:^(id  _Nonnull result) {
        if ([[result objectForKey:@"success"] boolValue]) {
            NSDictionary * field = result[@"field"];
            block(YES, field);
        } else {
            [self showErrorText:[result objectForKey:@"tips"]];
            block(NO, nil);
        }
    } errorHandle:^(NSError * _Nonnull error) {
        XWXNetError
        block(NO, nil);
    }];
}

//启动任务应用
+ (void)openTaskAppWithDownloadID:(NSString *)downloadID Block:(void(^)(BOOL isSuccess, NSDictionary *field))block {
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"DownloadID"] = downloadID;
    
    [[XWXNetWorkQuery sharedManage] AFRequestData:Url(URLShowdownApp) HttpMethod:KGet HaveToken:YES params:param completionHandle:^(id  _Nonnull result) {
        if ([[result objectForKey:@"success"] boolValue]) {
            NSDictionary * field = result[@"field"];
            block(YES, field);
        } else {
            [self showErrorText:[result objectForKey:@"tips"]];
            block(NO, nil);
        }
    } errorHandle:^(NSError * _Nonnull error) {
        XWXNetError
        block(NO, nil);
    }];
}

//普通任务上报审核
+ (void)uploadTaskWithRewardID:(NSString *)rewardID RewardKey:(NSString *)rewardKey Name:(NSString *)name IdCard:(NSString *)idCard Phone:(NSString *)phone Block:(void(^)(BOOL isSuccess))block {
    
    NSString * xmlStr = [NSString stringWithFormat:@"<configurationRoot>\
    <item name=\"applyName\" value=\"%@\" stepname=\"真实姓名\" columnmode=\"文本选项\" />\
    <item name=\"applyMobile\" value=\"%@\" stepname=\"电话号码\" columnmode=\"手机号码\" />\
    <item name=\"applyIdCard\" value=\"%@\" stepname=\"身份证号码\" columnmode=\"身份证号码\" />\
    </configurationRoot>",name,phone,idCard];
    
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"RewardID"] = rewardID;
    param[@"RewardKey"] = rewardKey;
    param[@"SubmitXml"] = xmlStr;
    
    [[XWXNetWorkQuery sharedManage] AFRequestData:Url(URLUploadTask) HttpMethod:KGet HaveToken:YES params:param completionHandle:^(id  _Nonnull result) {
        if ([[result objectForKey:@"success"] boolValue]) {
            block(YES);
        } else {
            [self showErrorText:[result objectForKey:@"tips"]];
            block(NO);
        }
    } errorHandle:^(NSError * _Nonnull error) {
        XWXNetError
        block(NO);
    }];
}

//截图任务提交接口
+ (void)submitTaskWithParam:(NSMutableDictionary *)param Block:(void(^)(BOOL isSuccess))block {
    
    [[XWXNetWorkQuery sharedManage] AFRequestData:Url(URLSubmitTask) HttpMethod:KGet HaveToken:YES params:param completionHandle:^(id  _Nonnull result) {
        if ([[result objectForKey:@"success"] boolValue]) {
            block(YES);
        } else {
            [self showErrorText:[result objectForKey:@"tips"]];
            block(NO);
        }
    } errorHandle:^(NSError * _Nonnull error) {
        XWXNetError
        block(NO);
    }];
    
}


//获取多游任务列表
+ (void)getMyTaskGameListWithAppId:(NSString *)appId Key:(NSString *)secretKey PageNum:(NSInteger)page Block:(void(^)(BOOL isSuccess, NSArray <LCGameTaskModel *>* list))block {
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"media_id"] = appId;
    param[@"user_id"] = LCUserDefGet(Userid);
    param[@"device_type"] = @"1";
    
    NSMutableArray * paramStrArr = [LCFunction  keyVauleArrWithDictionary:param].mutableCopy;
    [paramStrArr addObject:[NSString stringWithFormat:@"key=%@",secretKey]];
    NSString * paramStr = [paramStrArr componentsJoinedByString:@"&"];
    NSString * sign = [[LCFunction ns_md5:paramStr] lowercaseString];
    param[@"size"] = @(10);
    param[@"page"] = @(page);
    param[@"sign"] = sign;
    
    [[LCTaskService sharedManager] GET:URLMyTaskGame parameters:param headers:@{} progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([responseObject[@"status_code"] integerValue] == 200) {
            NSArray * list = [LCGameTaskModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]];
            block(YES, list);
        } else {
            [self showErrorText:[responseObject objectForKey:@"message"]];
            block(NO, nil);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        XWXNetError;
        block(NO, nil);
    }];
}

//获取我的任务列表
+ (void)myTaskListWithPage:(NSInteger)page Status:(NSString *)status Block:(void(^)(BOOL isSuccess, NSArray <LCMyTaskModel *>* list, NSInteger total))block {
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"isFast"] = status;
    param[@"page"] = @(page);
    
    [[XWXNetWorkQuery sharedManage] AFRequestData:Url(URLMyTaskList) HttpMethod:KGet HaveToken:YES params:param completionHandle:^(id  _Nonnull result) {
        if ([[result objectForKey:@"success"] boolValue]) {
            NSArray * list = [LCMyTaskModel mj_objectArrayWithKeyValuesArray:result[@"result"]];
            NSInteger total = [result[@"record"] integerValue];
            block(YES, list, total);
        } else {
            [self showErrorText:[result objectForKey:@"tips"]];
            block(NO, nil, 0);
        }
    } errorHandle:^(NSError * _Nonnull error) {
        XWXNetError
        block(NO, nil, 0);
    }];
}

//获取任务详情
+ (void)taskDetailWithAppId:(NSString *)appid LaunchId:(NSString *)launchid Block:(void(^)(BOOL isSuccess, LCTaskDetailModel * taskDetail))block {
    
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"AppID"] = appid;
    param[@"LaunchID"] = launchid;
    
    [[XWXNetWorkQuery sharedManage] AFRequestData:Url(URLTaskDetail) HttpMethod:KGet HaveToken:YES params:param completionHandle:^(id  _Nonnull result) {
        if ([[result objectForKey:@"success"] boolValue]) {
            LCTaskDetailModel * detail = [LCTaskDetailModel mj_objectWithKeyValues:result[@"field"]];
            detail.extend = [LCTaskDetailExtendModel mj_objectWithKeyValues:result[@"extend"]];
            block(YES, detail);
        } else {
            [self showErrorText:[result objectForKey:@"tips"]];
            block(NO, nil);
        }
    } errorHandle:^(NSError * _Nonnull error) {
        XWXNetError
        block(NO, nil);
    }];
}

+ (void)getStudyListWithClassID:(NSString *)classid Page:(NSInteger)page SearchKey:(NSString *)searchKey Block:(void(^)(BOOL isSuccess, NSArray <LCStudyModel *>* list, NSInteger total))block {
    NSMutableDictionary * param = [NSMutableDictionary dictionary];
    param[@"ClassID"] = classid;
    param[@"page"] = @(page);
    param[@"strKeywords"] = searchKey;
    [[XWXNetWorkQuery sharedManage] AFRequestData:Url(URLStudtList) HttpMethod:KGet HaveToken:NO params:param completionHandle:^(id  _Nonnull result) {
        if ([[result objectForKey:@"success"] boolValue]) {
            NSArray * list = [LCStudyModel mj_objectArrayWithKeyValuesArray:result[@"result"]];
            NSInteger total = [result[@"record"] integerValue];
            block(YES, list, total);
        } else {
            [self showErrorText:[result objectForKey:@"tips"]];
            block(NO, nil, 0);
        }
    } errorHandle:^(NSError * _Nonnull error) {
        XWXNetError;
        block(NO, nil, 0);
    }];
}



@end
